package com.offcn.search.controller;

import com.offcn.entity.Result;
import com.offcn.entity.StatusCode;
import com.offcn.search.service.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SkuController {

    @Autowired
    private SkuService skuService;

    @GetMapping("/import")
    public Result searchImport(){
        skuService.importSkuData();
        return new Result(true, StatusCode.OK,"sku数据导入成功");
    }

    @PostMapping
    public Map search(@RequestBody Map searchMap){
        Integer pageNum = (Integer) searchMap.get("pageNum");
        Integer pageSize = (Integer) searchMap.get("pageSize");
        if(pageNum!=null) {
            searchMap.put("pageNum", pageNum + "");
        }
        if(pageSize!=null) {
            searchMap.put("pageSize", pageSize + "");
        }
        Map map=new HashMap<>();
        map.put("code",20000);
        map.put("data",skuService.search(searchMap));
        return  map;
    }
}
